package com.franklin.ideaplugin.api.beans.declaration.impl;

import com.franklin.ideaplugin.api.beans.declaration.IDeclaration;
import com.franklin.ideaplugin.api.beans.variable.IVariable;
import com.franklin.ideaplugin.api.beans.variable.impl.LocalVariableVariable;
import com.intellij.psi.PsiDeclarationStatement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLocalVariable;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;

/**
 * @author Ye Junhui
 * @since 2024/3/6
 */
public class DeclarationStatementDeclaration implements IDeclaration {

    private PsiDeclarationStatement psiDeclarationStatement;

    public DeclarationStatementDeclaration(PsiDeclarationStatement psiDeclarationStatement) {
        this.psiDeclarationStatement = psiDeclarationStatement;
    }

    @Override
    public IVariable<PsiLocalVariable> getVariable() {
        PsiLocalVariable psiLocalVariable = (PsiLocalVariable) psiDeclarationStatement.getDeclaredElements()[0];
        return new LocalVariableVariable(psiLocalVariable);
    }

    @Override
    public @NotNull PsiElement getPsiElement() {
        return this.psiDeclarationStatement;
    }

    @Override
    public PsiType getPsiType() {
        return getVariable().getPsiType();
    }

}
